
using System;
using System.Collections.Generic;
using BTKERP.Model;
using BTKERP.DAL.DataAccess;
using System;

namespace BTKERP.DAL
{
	#region CategoryDAL
	public class CategoryDAL : DBContext
	{
		public List<Category> GetAll()
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CategoriesSelectAll");
            return GetEntityList<Category>(cmd);
        }

        public Category GetById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CategorySelect");
            cmd.AddParameter("@Id", id);
            return GetSingleEntity<Category>(cmd);
        }

        public Category Add(string paramName, string paramDescription, string paramCreatedBy)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CategoryInsert");
            cmd.AddParameter("@Name", paramName);
            cmd.AddParameter("@Description", paramDescription);
            cmd.AddParameter("@CreatedBy", paramCreatedBy);
            return GetSingleEntity<Category>(cmd);
        }

		public List<Category> GetByDynamicSQL(string sqlCondition)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CategorySelectDynamic");
            cmd.AddParameter("@SQL", sqlCondition);
            return GetEntityList<Category>(cmd);
        } 
		
        public bool DeleteById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CategoryDelete");
            cmd.AddParameter("@Id", id);
            return ExecuteCommand(cmd);
        }

        public Category UpdateById(Guid paramId, string paramName, string paramDescription, string paramUpdatedBy)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_CategoryUpdate");
			cmd.AddParameter("@Id", paramId);
			cmd.AddParameter("@Name", paramName);
			cmd.AddParameter("@Description", paramDescription);
			cmd.AddParameter("@UpdatedBy", paramUpdatedBy);
            return  GetSingleEntity<Category>(cmd);
        }
		
	}
	#endregion
}
